﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary.Geometry
{
    /// <summary>
    /// This class provides a container for geometric objects.
    /// </summary>
    [Serializable]
    public class GeometyContainer : IGeometyContainer
    {
        private List<GeometricObject> container;

        /// <summary>
        /// Initializes a new instance of the <see cref="GeometyContainer"/> class.
        /// </summary>
        public GeometyContainer()
        {
            this.container = new List<GeometricObject>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GeometyContainer"/> class.
        /// </summary>
        /// <param name="data">The list of geometric object.</param>
        public GeometyContainer(List<GeometricObject> data)
        {
            if (data == (List<GeometricObject>) null)
            {
                throw new ArgumentNullException("data");
            }

            this.container = new List<GeometricObject>();

            foreach (GeometricObject o in data)
            {
                this.container.Add(o);
            }
        }

        /// <summary>
        /// Gets or sets the data for the container.
        /// </summary>
        /// <value>The data for the container.</value>
        public List<GeometricObject> Container
        {
            get { return container; }
            set { container = value; }
        }

        /// <summary>
        /// Counts the number of geometric objects, which the current 
        /// instance includes.
        /// </summary>
        /// <value>The number of geometric objects which the current 
        /// instance includes.</value>
        public int Count
        {
            get { return container.Count; }
        }

        /// <summary>
        /// Adds a new geometric object to the container.
        /// </summary>
        /// <param name="value">The geometric object to add to the container.</param>
        public void Add(GeometricObject value)
        {
            this.container.Add(value);
        }

        /// <summary>
        /// Removes all object from the container.
        /// </summary>
        public void Clear()
        {
            this.container.Clear();
        }

        /// <summary>
        /// Removes the geometric object at a specified index.
        /// </summary>
        /// <param name="index">The specified index from the object which should be removed.</param>
        public void RemoveAt(int index)
        {
            this.container.RemoveAt(index);
        }

        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns>The enumerator of the current iteration.</returns>
        public IEnumerator<GeometricObject> GetEnumerator()
        {
            for (int i = 0; i < this.container.Count; i++)
            {
                yield return this.container[i];
            }
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
        /// <returns>
        /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
        /// </returns>
        /// <exception cref="T:System.NullReferenceException">The <paramref name="obj"/> parameter is null.</exception>
        public override bool Equals(object obj)
        {
            return base.Equals(obj);
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return base.ToString();
        }
    }
}